﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CreatingRainbows
{
    public class Actor : DrawableGameComponent
    {
        protected SpriteBatch spriteBatch;

        //What its going to look like
        protected Texture2D texture;

        //Where it is
        public Vector2 position;

        //How big is it?
        public Rectangle source;

        //What color is it?
        public Color color;

        protected Single rotation;

        protected Vector2 origin;

        //How much bigger or smaller than it's original size?
        protected Vector2 scale;

        protected SpriteEffects effects;

        protected Single depth;

        // Constructor
        public Actor(Game1 game)
            : base(game)
        {
            //game.Components.Add(this);
            // Do nothing
        }

        // Initialization
        public void Initialize(Vector2 pos, Rectangle src, Color color, Vector2 origin, Vector2 scale, Single depth)
        {
            // Initialize user input variables
            this.position = pos;
            this.source = src;
            this.color = color;
            this.origin = origin;
            this.scale = scale;
            this.depth = depth;

            // Initialize constant variables
            this.rotation = 0;
            this.effects = SpriteEffects.None;
        }

        // Load all content used
        public void LoadContent(SpriteBatch spriteBatch, ref Texture2D texture)
        {
            // Load user input content
            this.spriteBatch = spriteBatch;
            this.texture = texture;
        }

        // Draw to the screen
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(this.texture, this.position, this.source, this.color, this.rotation, this.origin, this.scale, this.effects, this.depth);
            spriteBatch.End();

            base.Draw(gameTime);
        }

        public void SetPosition(Vector2 position)
        {
            this.position = position;
        }

        public bool Colliding(Actor otherSprite)
        {
            if (this.position.X + this.source.Width > otherSprite.position.X &&
                this.position.X < otherSprite.position.X + otherSprite.source.Width &&
                this.position.Y + (.5 * this.source.Height) > otherSprite.position.Y &&
                this.position.Y < otherSprite.position.Y + otherSprite.source.Height)
            {
                return true;
            }
            return false;
        }

        public bool MouseOver(int x, int y)
        {
            if ((x > this.position.X && x < this.position.X + this.source.Width) && (y > this.position.Y && y < this.position.Y + this.source.Height))
            {
                return true;
            }

            return false;
        }
    }
}